<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="/paginas/templates/commonLayout.xhtml">

	<ui:define name="title">
		Listagem de Processos
	</ui:define>

	<ui:define name="content">

		<p:panel style="text-align: center;">
			<h2>Listagem dos Processos</h2>
		</p:panel>

		<br />

		<h:form>

			<p:fieldset legend="Opções" style="width:300px;">
				<br />
				<p:commandButton value="Criar Processo" icon="ui-icon-document"
					ajax="false" action="#{processoBean.paginaCriarProcesso}" />

			</p:fieldset>
		</h:form>

		<p:growl id="growlProcessos" showDetail="false" sticky="false"
			life="6000" />
		<br />


		<p:panel header="Processos Salvos" style="text-align: center;">

			<h:form id="processosSalvoForm">


				<p:dataTable id="processosSalvosEtapa" var="processo"
					paginator="true" rows="10" style="text-align: center;"
					selection="#{processoBean.processo}" selectionMode="single"
					value="#{processoBean.processos}"
					paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
					rowKey="#{processo.id}" rowsPerPageTemplate="10,15,20"
					emptyMessage="Nenhum processo encontrado.">

					<p:ajax event="rowSelect" />

					<p:column headerText="Número do Processo">
						<h:outputText value="#{processo.numero}" />
					</p:column>

					<p:column headerText="Data do Processo">
						<h:outputText value="#{processo.data}" />
					</p:column>

					<p:column headerText="Setor">
						<h:outputText value="#{processo.setor.tipoSetor}" />
					</p:column>

					<p:column headerText="Autor">
						<h:outputText value="#{processo.usuario.nome}" />
					</p:column>

					<p:column headerText="Observação">
						<h:outputText value="#{processo.observacao}" />
					</p:column>

					<f:facet name="footer">
						<p:commandButton value="Parecer" icon="ui-icon-check"
							action="#{processoBean.inicializaParecer}"
							onclick="parecerProcessoDialog.show()" />

						<p:commandButton icon="ui-icon-search" value="Verificar Pareceres"
							update=":visualizarPareceresForm:visualizarPareceresPanel"
							label="Verificar" onclick="visualizarPareceresDialog.show()" />

						<p:commandButton value="Editar" icon="ui-icon-document"
							action="#{processoBean.paginaEditarProcesso}" ajax="false" />

						<p:commandButton value="Deletar" icon="ui-icon-trash"
							rendered="#{usuarioBean.ehAdministrador}"
							onclick="deletarDialog.show()" />

					</f:facet>


				</p:dataTable>

			</h:form>

			<h:form>
				<p:dialog id="parecerProcesso" header="Parecer do Processo"
					widgetVar="parecerProcessoDialog" rendered="#{processoBean.processo != null}">
					<p:panel>
						<h:panelGrid id="panelParecer" columns="2" cellpadding="5">

							<h:outputLabel for="novoSetorProcesso"
								value="Enviar para o Setor:" />
							<p:selectOneMenu id="novoSetorProcesso"
								value="#{processoBean.processo.setor}" effect="fade"
								converter="setorConverter">
								<f:selectItems value="#{processoBean.tiposSetores}"
									required="true" var="setor" itemLabel="#{setor.tipoSetor}"
									itemValue="#{setor}" />
							</p:selectOneMenu>

							<h:outputLabel for="resultadoParecer"
								value="Resultado do Parecer:" />
							<p:selectOneMenu id="resultadoParecer"
								value="#{processoBean.parecerProcesso.resultado}">
								<f:selectItem itemLabel="Deferido" itemValue="Deferido" />
								<f:selectItem itemLabel="Indeferido" itemValue="Indeferido" />
							</p:selectOneMenu>

						</h:panelGrid>

						<h:panelGrid id="panelDescParecer" columns="2" cellpadding="5">

							<h:outputLabel value="Descrição do parecer:" for="descParecer" />
							<p:inputTextarea id="descParecer" rows="3" cols="50"
								maxLength="255"
								value="#{processoBean.parecerProcesso.descricao}" />

						</h:panelGrid>

					</p:panel>

					<h:panelGrid id="panelBotoesParecer" columns="2" cellpadding="5">


						<p:commandButton value="Confirmar Parecer"
							action="#{processoBean.salvarParecer}" process="@form"
							update=":processosSalvoForm:processosSalvosEtapa,:growlProcessos"
							oncomplete="parecerProcessoDialog.hide()" />

						<p:commandButton value="Cancelar"
							onclick="parecerProcessoDialog.hide()" type="button" />

					</h:panelGrid>

				</p:dialog>

			</h:form>

			<p:dialog id="visualizarPareceres" header="Pareceres enviados" width="700"
				modal="true" widgetVar="visualizarPareceresDialog" closable="true"
				dynamic="true" maximizable="true" minimizable="false"
				rendered="#{processoBean.processo != null}">

				<h:form id="visualizarPareceresForm">
					
					<p:panel id="visualizarPareceresPanel">
						<h:panelGrid id="panelDadosProcesso" columns="2" cellpadding="1">
							
							<h:outputLabel for="numeroProc" value="Processo Número:" style="font-weight:bold" />
							<h:outputText id="numeroProc" value="#{processoBean.processo.numero}" />
							
							<h:outputLabel for="dataProc" value="Data do Processo:" style="font-weight:bold" />
							<h:outputText id="dataProc" value="#{processoBean.processo.data}" />
							
							<h:outputLabel for="autorProc" value="Autor do Processo:" style="font-weight:bold" />
							<h:outputText id="autorProc" value="#{processoBean.processo.usuario.nome}" />
							
							<h:outputLabel for="descProc" value="Observação do Processo:" style="font-weight:bold" />
							<h:outputText id="descProc" value="#{processoBean.processo.observacao}" />
							
							
							
						</h:panelGrid>
						

						<p:dataTable id="pareceresEnviados" var="parecer" paginator="true"
							rows="10"
							value="#{processoBean.processo.pareceres}"
							paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
							rowKey="#{parecer.id}" emptyMessage="Nenhum parecer encontrado.">
							
							<p:column headerText="Autor">
								<h:outputText value="#{parecer.autor.nome}" />
							</p:column>

							<p:column headerText="Resultado">
								<h:outputText value="#{parecer.resultado}" />
							</p:column>

							<p:column headerText="Descrição">
								<h:outputText value="#{parecer.descricao}" />
							</p:column>

						</p:dataTable>

					</p:panel>
				</h:form>
			</p:dialog>



			<h:form>
				<!-- DIALOG DELETAR PROCESSO	 -->
				<p:confirmDialog id="deletarDialog"
					message="Deseja realmente deletar o processo selecionado?"
					header="Deletar o Processo" severity="alert"
					widgetVar="deletarDialog">

					<p:commandButton value="Sim"
						action="#{processoBean.deletarProcesso}"
						update=":processosSalvoForm:processosSalvosEtapa,:growlProcessos"
						oncomplete="deletarDialog.hide()" />

					<p:commandButton value="Não" onclick="deletarDialog.hide()"
						type="button" />
				</p:confirmDialog>

			</h:form>
		</p:panel>




	</ui:define>
</ui:composition>



</html>